<template lang="">
    <div class="recommendContainer">
        <el-form :inline="true" :model="params" class="demo-form-inline">
            <el-form-item label="岗位:">
               <el-input v-model="params.name" placeholder="请输入" class="inputBorder"></el-input>
            </el-form-item>
            <el-form-item label="类别:">
               <el-select v-model="params.kind" placeholder="请选择">
                   <el-option label="内部" value="0"></el-option>
                   <el-option label="外部" value="1"></el-option>
               </el-select>
            </el-form-item>
            <el-form-item label="工作内容:">
               <el-input v-model="params.jobDuty" placeholder="请输入"></el-input>
            </el-form-item>
            <br>
            <el-form-item style="float:right">
                <el-button type="primary" @click="onSubmit" style="background:#4787E3FF">查询</el-button>
                <el-button type="primary" @click="onDelete" style="background:#4787E3FF">删除</el-button>
            </el-form-item>
        </el-form>

         <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" :header-cell-style="{background:'#4787E3FF',color:'#fff'}" style="width: 100%" @select="select" @select-all="selectAll" >
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="username" label="姓名" width="120"></el-table-column>
            <el-table-column prop="kindType" label="类别" width="120"></el-table-column>
            <el-table-column prop="jobName" label="推荐岗位" width="120"></el-table-column>
            <el-table-column prop="time" label="推荐时间" width="120"></el-table-column>
            <el-table-column prop="introduceUser" label="推荐人" width="120"></el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
                    <el-button @click="open(scope.row)" type="text" size="small">删除</el-button>
                    <el-button type="text" size="small">下载</el-button>
                </template>
            </el-table-column>
        </el-table>
        
        <!-- 分页 -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage1"
          :page-size="3"
          layout="total, prev, pager, next"
          background
          :total="totalCount">
        </el-pagination>
        <Look :val="dialogVisible" :menuForm="menuForm"  @getMessage='close'></Look>
    </div>
</template>

<script>
import Look from './actions/look' 
export default {
  data() {
    return {
      //查询条件
      formInline: {
        post: "",
        type: "",
        jobcontent: ""
      },
      dialogVisible:false,   
      menuForm:{},
      tableData: [],//表格数据
      multipleSelection: [], //多选数组
      id:0,
      ids:[],//删除选择的数组
      params: {
        name: "",
        kind:"",
        jobDuty:"",
        page: 1,
        pageSize: 4
      },
      currentPage1: 1,
      totalCount:0, // 总条数
      // menuForm:{}//查看中的数据

    };
  },
  methods: {
    //得到表格数据
    async getRecommendList(){
      const { data: res }= await this.$http.post("qryIntroducePc", this.params);
      for(let i=0;i<res.data.recruitmentBackPCS.length;i++){
        //处理时间戳
        let timer = res.data.recruitmentBackPCS[i].time
        var date = new Date(parseInt(timer));
        var Y = date.getFullYear() + '/';
        var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '/';
        var D = (date.getDate() + 1 < 10 ? '0' + (date.getDate() + 1) : date.getDate() + 1) ;
        res.data.recruitmentBackPCS[i].time = Y + M + D 
        //判断类别
        if(res.data.recruitmentBackPCS[i].kind == 0){
          res.data.recruitmentBackPCS[i].kindType = '内部' 
        }else{
          res.data.recruitmentBackPCS[i].kindType = '外部'
        }
      }
      this.tableData = res.data.recruitmentBackPCS   
      this.totalCount = res.data.totals
    },
    //分页
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.params.page = val
      this.getRecommendList()
    },
    //查询
    onSubmit() {
      this.getRecommendList();
    },
    //批量删除信息
    async onDelete(){
      if(this.ids.length == 0){
        alert("请选择删除项!");
        return;
      }
      const {data:res} =await this.$http.post("deleteIntroduceByList", this.ids)
      console.log(res)
      if(res.success == true){
        this.getRecommendList()
      }
    },
    //多选
    select(selection){
      let a = []
      selection.forEach(item => {
        a.push(item.id)
      })
      this.ids = a
    },
    //全选
    selectAll(selection){
      let a = []
      selection.forEach(item => {
        a.push(item.id)
      })
      this.ids = a
    },
    // 查看
    async handleClick(row){
      this.dialogVisible=true
      // 获取应聘信息详情 
      console.log('row',row)
      const { data: res }= await this.$http.get("qryIntroducePcById", {params:{id:row.id}});
      console.log('999',res)
      this.menuForm = res.data
      if(row.kind==0){ //内部
        this.menuForm.kind = 0
      }else { //外部
        this.menuForm.kind= 1
      }
      this.menuForm.time = row.time
       this.menuForm.edu = this.menuForm.edu==1?'大专':'本科'
      console.log(9999,this.menuForm)
    
    },
    close(val){
      this.dialogVisible=val
    },
    //删除单条信息
    async open(row){
      // console.log("shanchu",row);
      this.id =row.id
      const { data: res }= await this.$http.get("deleteByIntroduceId",{params:{id:this.id}})
      if(res.data == 1){
        this.getRecommendList()
      }
    }
  },
  created(){
      this.getRecommendList()
  },
  components:{
      'Look':Look
  }
};
</script>

<style lang="less">
.recommendContainer {
  background-color: #fff;
  margin-top: 4px;
  padding: 20px 0 0 30px;
}
//  .inputBorder {
//     border: 1px solid blue!important;
//  }
</style>